﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Moe_v0._1
{
    class Phrase
    {
        private List<string> _wordsList = null;
        private string _originalInput = "";
        public Phrase(string input)
        {
            _originalInput = input;

            // Remove extra space at the beginning and end of the string.
            string tempString = input.TrimStart(' ');
            tempString = tempString.TrimEnd(' ');

            if (tempString.Length > 0)
            {
                // Not an empty phrase we tokenize it by ' ' and store it into _wordList.
                _wordsList = tempString.Split(' ').ToList();
            }
            else
            {
                // An empty phrase cause an empty list of word for the phrase.
                _wordsList = new List<string>();
            }
            
            // Ensure that _wordList the user gets is NOT null.
            Debug.Assert(_wordsList != null);

            if (MoeDebugger.IsDebugging)
            {
                MoeDebugger.AddDebugInfo("Phrase: For [" + _originalInput + "]");
                MoeDebugger.AddDebugInfo("Phrase: we have '" + _wordsList.Count + "' key words.");
                foreach (string word in _wordsList)
                {
                    MoeDebugger.AddDebugInfo("Phrase: <key word> " + word);
                }
            }
        }

        public List<string> KeyWordList
        {
            get
            {
                Debug.Assert(_wordsList != null);
                return _wordsList;
            }
        }
    }
}
